<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\LoginForm */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;

use backend\assets\AppAsset;
AppAsset::register($this);
AppAsset::addJs($this,Yii::$app->request->baseUrl."/js/a.js");


$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;

?>
<style>
    .content {
        background-color: #2b81af;
        width: 100%;
        height: 100%;
        padding-top:120px;
    }
    .login {
        margin: 0px auto 0 auto;
        min-height: 420px;
        max-width: 420px;
        padding: 40px;
        background-color: #ffffff;
        margin-left: auto;
        margin-right: auto;
        border-radius: 4px;
        /* overflow-x: hidden; */
        box-sizing: border-box;
    }
    .login .message {
        margin: 10px 0 0 -58px;
        padding: 18px 10px 18px 60px;
        background: #189F92;
        position: relative;
        color: #fff;
        font-size: 16px;
    }
    .login #darkbannerwrap {
        background: url("<?=Yii::$app->request->baseUrl."/static/images/aiwrap.png"?>");
        width: 18px;
        height: 10px;
        margin: 0 0 20px -58px;
        position: relative;
    }
    .login hr {
        background: #fff 0 0 no-repeat;
    }
    .login hr.hr15 {
        height: 15px;
        border: none;
        margin: 0px;
        padding: 0px;
        width: 100%;
    }
    .login hr.hr20 {
        height: 20px;
        border: none;
        margin: 0px;
        padding: 0px;
        width: 100%;
    }
    .login input {
        height:50px;
    }

</style>
<div class="content">
    <div class="login">
        <div class="message">Admin 1.0-管理登录</div>
        <div id="darkbannerwrap"></div>

        <?php $form = ActiveForm::begin([
            'id' => 'login-form',
            'method' => 'post',
            //'layout' => 'horizontal',
            'fieldConfig' => [
                'template' => "{input}",
            ],
            'options' => [
                'class' => 'layui-form'
            ]
        ]); ?>

        <?= Html::textInput('username', null,  ['autofocus' => true,'placeholder'=>'用户名', 'class'=>'layui-input', 'lay-verify'=>'required']) ?>
        <hr class="hr15">
        <?= Html::passwordInput('password', null, ['placeholder'=>'密码', 'class'=>'layui-input', 'lay-verify'=>'required']) ?>
        <hr class="hr15">
        <?= Html::submitInput('登录', ['class' => 'layui-btn layui-btn-fluid', 'lay-submit' => '', 'lay-filter'=>'login']) ?>
        <hr class="hr20" >
        <div>
            测试中 admin admin，即可登录。
        </div>
        <?php ActiveForm::end(); ?>
    </div>
</div>
<script>
    <?php $this->beginBlock('js') ?>
    layui.use(['form'], function () {
        var form = layui.form;
        form.on('submit(login)', function(data){
            $.ajax({
                url: '<?=Url::to()?>',
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (result) {
                    if(result.status == 200){
                        location.href = '<?=Url::home()?>';
                    }else{
                        layer.close(layer.index);
                        layer.msg(result.msg);
                    }
                },
                error: function (e) {
                    layer.close(layer.index);
                    layer.msg('网络错误,请重试');
                }
            });
            return false;
        });
    });
    <?php $this->endBlock() ?>
    <?php $this->registerJs($this->blocks['js'], \yii\web\View::POS_END); ?>
</script>